package com.edu.bhu.admin.service.impl;

import java.util.List;
import java.util.stream.Collectors;

import com.edu.bhu.admin.domain.PreArea;
import com.edu.bhu.common.core.domain.entity.SysUser;
import com.edu.bhu.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.edu.bhu.admin.mapper.PreBodyMapper;
import com.edu.bhu.admin.domain.PreBody;
import com.edu.bhu.admin.service.IPreBodyService;
import com.edu.bhu.common.core.text.Convert;

/**
 * 身体状况Service业务层处理
 * 
 * @author yutianyang
 * @date 2022-04-23
 */
@Service
public class PreBodyServiceImpl implements IPreBodyService 
{
    @Autowired
    private PreBodyMapper preBodyMapper;

    @Autowired
    private SysUserMapper sysUserMapper;

    /**
     * 查询身体状况
     * 
     * @param bodyId 身体状况主键
     * @return 身体状况
     */
    @Override
    public PreBody selectPreBodyByBodyId(Long bodyId)
    {
        return preBodyMapper.selectPreBodyByBodyId(bodyId);
    }

    /**
     * 查询身体状况列表
     * 
     * @param preBody 身体状况
     * @return 身体状况
     */
    @Override
    public List<PreBody> selectPreBodyList(PreBody preBody)
    {
        List<PreBody> list = preBodyMapper.selectPreBodyList(preBody);
        list = list.stream().map(m ->{
            SysUser sysUser = sysUserMapper.selectUserById(m.getUserId());
            m.setSysUser(sysUser);
            return m;
        }).collect(Collectors.toList());
        return list;
    }

    /**
     * 新增身体状况
     * 
     * @param preBody 身体状况
     * @return 结果
     */
    @Override
    public int insertPreBody(PreBody preBody)
    {
        return preBodyMapper.insertPreBody(preBody);
    }

    /**
     * 修改身体状况
     * 
     * @param preBody 身体状况
     * @return 结果
     */
    @Override
    public int updatePreBody(PreBody preBody)
    {
        return preBodyMapper.updatePreBody(preBody);
    }

    /**
     * 批量删除身体状况
     * 
     * @param bodyIds 需要删除的身体状况主键
     * @return 结果
     */
    @Override
    public int deletePreBodyByBodyIds(String bodyIds)
    {
        return preBodyMapper.deletePreBodyByBodyIds(Convert.toStrArray(bodyIds));
    }

    /**
     * 删除身体状况信息
     * 
     * @param bodyId 身体状况主键
     * @return 结果
     */
    @Override
    public int deletePreBodyByBodyId(Long bodyId)
    {
        return preBodyMapper.deletePreBodyByBodyId(bodyId);
    }
}
